package com.xx.sg.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.xx.sg.own.entity.CameraPlan;
import com.xx.sg.own.service.CameraPlanService;
import com.xx.sg.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cameraPlan")
@Tag(name = "监控方案", description = "监控方案API")
public class CameraPlanController {

    @Autowired
    private CameraPlanService cameraPlanService;

    @GetMapping("/list")
    @Operation(summary = "获取监控方案列表", description = "获取监控方案列表")
    public R list(CameraPlan plan) {
        LambdaQueryWrapper<CameraPlan> wrapper = new LambdaQueryWrapper<CameraPlan>();
        wrapper.eq(StringUtils.isNotBlank(plan.getPlanName()), CameraPlan::getPlanName, plan.getPlanName())
                .orderByDesc(CameraPlan::getCreateTime);
        List<CameraPlan> list = cameraPlanService.list(wrapper);
        return R.success(list);
    }

    @GetMapping("/info/{id}")
    @Operation(summary = "获取监控方案信息", description = "获取监控方案信息")
    public R info(@PathVariable("id") String id) {
        CameraPlan cameraPlan = cameraPlanService.getById(id);
        return R.success(cameraPlan);
    }

    @PostMapping("/add")
    @Operation(summary = "新增监控方案信息", description = "新增监控方案信息")
    public R add(@RequestBody CameraPlan cameraPlan) {
        cameraPlanService.save(cameraPlan);
        return R.success(cameraPlan);
    }

    @PostMapping("/modify")
    @Operation(summary = "修改监控方案信息", description = "修改监控方案信息")
    public R modify(@RequestBody CameraPlan cameraPlan) {
        cameraPlanService.updateById(cameraPlan);
        return R.success(cameraPlan);
    }

    @GetMapping("/remove/{id}")
    @Operation(summary = "删除监控方案", description = "删除监控方案")
    public R remove(@PathVariable("id") String id) {
        cameraPlanService.removeById(id);
        return R.success();
    }
}
